import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { ResData, Status } from 'src/response/res-data.interface';
import { Repository } from 'typeorm';
import { CreateCustomFlowNodeDto } from './dto/create-custom-flow-node.dto';
import { UpdateCustomFlowNodeDto } from './dto/update-custom-flow-node.dto';
import { CustomFlowNode } from './entities/custom-flow-node.entity';

@Injectable()
export class CustomFlowNodeService {
  constructor(@InjectRepository(CustomFlowNode) private customFormNodeRepository: Repository<CustomFlowNode>) { }

  async create(createCustomFlowNodeDto: CreateCustomFlowNodeDto) {
    let resdata: ResData;
    try {
      const result = await this.customFormNodeRepository.save(createCustomFlowNodeDto);
      resdata = {
        code: Status.SUCCESS,
        msg: '保存成功',
        content: result
      };
      return resdata;
    } catch (e) {
      resdata = {
        code: Status.ERROR,
        msg: e,
      };
      return resdata;
    }
  }

  findAll() {
    return `This action returns all customFlowNode`;
  }

  findOne(id: number) {
    return `This action returns a #${id} customFlowNode`;
  }

  update(id: number, updateCustomFlowNodeDto: UpdateCustomFlowNodeDto) {
    return `This action updates a #${id} customFlowNode`;
  }

  async remove(id: string) {
    let resdata: ResData;
    try {
      const result = await this.customFormNodeRepository.delete(id);
      resdata = {
        code: Status.SUCCESS,
        msg: '删除成功',
        content: result
      };
      return resdata;
    } catch (e) {
      resdata = {
        code: Status.ERROR,
        msg: e,
      };
      return resdata;
    }
  }
}
